import Vue from 'vue'
import Vuex from 'vuex'
import app from './modules/app'
import dict from './modules/dict'
import user from './modules/user'
import tagsView from './modules/tagsView'
import permission from './modules/permission'
import settings from './modules/settings'
import getters from './getters'

import createPersistedState from "vuex-persistedstate";

Vue.use(Vuex)

const store = new Vuex.Store({
  plugins: [createPersistedState({
    key: process.env.VUE_APP_STORE_KEY || 'vuex',
    storage: window.localStorage,
    reducer(val) {
        return {
          // 只持久化必要的状态
          user: {
            token: val.user.token,
            id: val.user.id,
            name: val.user.name,
            nickName: val.user.nickName,
            avatar: val.user.avatar,
            position: val.user.position,
            permissions: val.user.permissions
          },
          settings: val.settings,
          tagsView: val.tagsView    // 看你需不需要
        }
      }
  })],
  modules: {
    app,
    dict,
    user,
    tagsView,
    permission,
    settings
  },
  getters
})

export default store
